package com.aaa.mythread;

public class MyThread5scaleticket extends Thread{

    private Object object = new Object();


    private int ticket=1000;


    @Override
    public void run() {
        //  业务

       while (true) {

           // synchronized （锁对象）{}
           synchronized (object) {
               if (ticket > 0) {
                   //  1
                   // 1
                   System.out.println(Thread.currentThread().getName() + "卖出了一张票，还有" + ticket--);
               }
           }

       }

    }


    public static void main(String[] args) {
        MyThread5scaleticket myThread4scaleticket = new MyThread5scaleticket();
        Thread thread = new Thread(myThread4scaleticket,"zs");// 4  2
        Thread thread2 = new Thread(myThread4scaleticket,"ls");// 3 3
        Thread thread3 = new Thread(myThread4scaleticket,"ww");// 3 3


        thread.start();
        thread2.start();
        thread3.start();


    }
}
